#include <iostream>

using namespace std;

bool verifySquenceOfBST(int *a, int len)
{
	if(len == 0)
		return true;

	int k = 0;
	for(; k < len - 1; k++)
		if(a[k] > a[len - 1])
			break;
	
	bool flag = true;
	for(int i = k; i < len - 1; i++)
		if(a[i] < a[len - 1])
			flag = false;
	
	return flag && verifySquenceOfBST(a, k) && verifySquenceOfBST(a + k, len - k -1 );
}

int main()
{
	//int a[7] = {5, 7, 6, 9, 11, 10, 8};
	int a[7] = {7, 4, 6, 5};
	cout<<verifySquenceOfBST(a, 4)<<endl;;
}
